package base.collections.concurrenthashmap;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

/**
 *
 * @author scylla
 * @version V1.0
 * @project echo-java-base
 * @title ConcurrentHashMap
 * @package base.collections.concurrenthashmap
 * @since 2023/1/9 5:58 下午
 */
public class NewConcurrentHashMap {


    public static void main(String[] args) {
        ConcurrentHashMap<String, Object> map = new ConcurrentHashMap<>();
        map.put("a", "newaa");
        map.put("b", "newbb");
        try {

            Thread run1 = new Thread(() -> {
                for (Map.Entry<String,Object> entry : map.entrySet()) {
                    try {
                        TimeUnit.MILLISECONDS.sleep(1000L);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(entry.getKey() + "::" + entry.getValue());
                }
            });
            run1.start();

            TimeUnit.MILLISECONDS.sleep(100L);
            map.put("g", "newcc");

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

}
